/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package verins.Utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author Hector
 */
public class Conexion {

    static Connection conn=null;
    /*
    static public String strConex="jdbc:postgresql://127.0.0.1:5432/veri";
    static public String user="postgres";
    static public String pass="contra";
    
     */
    
    static public String strConex="jdbc:postgresql://quilla.lab.inf.pucp.edu.pe:1042/postgres";
    static public String user="postgres";
    static public String pass="victoria"; 
    
    
    public Connection getConexion(){
         try {

                    Class.forName("org.postgresql.Driver");

            } catch (ClassNotFoundException e) {

                    System.out.println("Where is your PostgreSQL JDBC Driver? "
                                    + "Include in your library path!");
                    e.printStackTrace();
                    return null;

            }

            Connection connection = null;

            try {
               connection = DriverManager.getConnection(strConex, user,pass);

               if (connection != null) {
                    System.out.println("You made it, take control your database now!");
                } else {
                        System.out.println("Failed to make connection!");
                }
               conn=connection;
               return  conn;
               
               
            } catch (SQLException e) {

                    System.out.println("Connection Failed! Check output console");
                    e.printStackTrace();
                    return null;

            }

            
    }
    
     public void close(){
         
         if (conn!=null)
             try {
            conn.close();
        } catch (SQLException ex) {
            //Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
        }
     }


}
